
#coding=utf-8
'''
Created on Aug 2, 2016

@author: wangpeng
'''
import unittest
from appium import webdriver
from selenium.webdriver.common.by import By   #用于匹配某个值是否出现，智能等待
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
import time
import common.logging_save_huawei_5x
import common.desired_setting_huawei_5x
import common.config
import common.Create_Log_Folder
import sys
reload(sys)
sys.setdefaultencoding('utf8')
import os
#icon_xpath = common.config.huawei_BT_setting_icon_open()
def test():
    desired_setting = common.desired_setting_huawei_5x.desired_setting()
    driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_setting)
    time.sleep(5)
    driver.start_activity("com.android.settings", ".HWSettings")
    common.logging_save_huawei_5x.logging.info("app测试开始，开始检测蓝牙名字是否对应")
    print time.ctime(),'打开蓝牙设置界面'
    time.sleep(5)
    driver.find_element_by_xpath("//android.widget.TextView[@text='蓝牙']").click()
    time.sleep(5)
    els_close = driver.find_elements_by_id('android:id/switchWidget')
    els_close[0].click()               #先关
    common.logging_save_huawei_5x.logging.info("关闭蓝牙开关")
    print time.ctime(),"打开蓝牙开关"
    time.sleep(5)
    els_close[0].click()               #再打开
    time.sleep(10)
    #手机端切换关掉手机的蓝牙开关，然后打开蓝牙开关，然后判断蓝牙是否处于连接状态
    if driver.find_elements_by_id(common.config.huawei_BT_setting_icon_open()):
        pass
        
    else:
        els_close[0].click()               #再打开
        common.logging_save_huawei_5x.logging.info("检测到蓝牙开关没有打开，重新打开")
        print time.ctime(),"检测到蓝牙开关没有打开，重新打开"
    
    driver.quit()  #关掉server，重新进入酷狗界面
    time.sleep(5)
    print time.ctime(),'华为device端开关蓝牙ok'
    common.logging_save_huawei_5x.logging.info("华为device端开关蓝牙ok")